package android.slc.mp.ui.page;

import android.content.Context;
import android.slc.ma.MaBaseAdapter;
import android.slc.ma.MaBaseViewHolder;
import android.slc.mp.R;
import android.slc.mp.po.i.IBaseItem;
import android.slc.mp.ui.SlcIMpDelegate;
import android.view.ViewGroup;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;

import java.util.List;

/**
 * Created by slc
 */
public abstract class SlcMpBaseMpAdapter<T extends IBaseItem> extends MaBaseAdapter<T> {
    public static final int ITEM_TYPE_DEF = 0;//默认item类型
    protected SlcIMpDelegate mMediaPickerDelegate;
    protected int lastPosition = -1;

    public SlcMpBaseMpAdapter(@LayoutRes int layoutRes, @NonNull Context context, @NonNull List<T> date,
                              SlcIMpDelegate mediaPickerDelegate) {
        super(context, date);
        mMediaPickerDelegate = mediaPickerDelegate;
        addLayoutByType(ITEM_TYPE_DEF, layoutRes);
    }

    @Override
    protected int getDefItemViewType(int position) {
        /*if (mData != null && !mData.isEmpty()) {
            T data = mData.get(position);
            return SlcMp.getMediaTypeByItem(data);
        }*/
        return super.getDefItemViewType(position);
    }

    public void notifyDataSwitch(int curPosition) {
        if (lastPosition != -1) {
            notifyItemChanged(lastPosition);
        }
        lastPosition = curPosition;
        notifyItemChanged(curPosition);
    }

    @Override
    protected MaBaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        MaBaseViewHolder slcMpBaseViewHolder = super.onCreateDefViewHolder(parent, viewType);
        slcMpBaseViewHolder.addOnClickListener(getClickCheckId());
        slcMpBaseViewHolder.addOnClickListener(getContentClickViewId());
        return slcMpBaseViewHolder;
    }

    @IdRes
    public int getClickCheckId() {
        return R.id.checkbox;
    }

    @IdRes
    public int getContentClickViewId() {
        return R.id.fl_content;
    }

}
